<?php
/**
 * app controller
 * @package app-member_controller
 */
load_controller('/api');
/**
 * app controller
 * @author pandajingjing
 * @package app-member_controller
 */
class appcontroller extends apicontroller{

	function doRequest(){
		$strAction=$this->getParam('action','url');
		$arrErrInfo=array();
		$this->setData('strAction',$strAction);
		$mixAppChk=$this->getData('mixAppChk');
		if(true===$mixAppChk){
			$strReturnURL=$this->getData('strReturnURL');
			switch($strAction){
				case 'login':
					$strAction=$this->getParam('hidAction','post');
					if('login'==$strAction){
						$strLoginValue=$this->getParam('txtLoginValue','post');
						$strUserPwd=$this->getParam('pwdUserPwd','post');
						load_lib('/bll/member/login');
						$clsLogin=new bll_member_login();
						$arrUserInfo=array();
						$mixResult=$clsLogin->loginUser($strLoginValue,$strUserPwd,$this->getClientIP(),$this->getTime(),$arrUserInfo);
						if(is_array($mixResult)){
							$arrErrInfo=$mixResult;
						}else{
							$this->setCookie('mauthcode',$clsLogin->encryptLoginInfo(array( 
									'USERID'=>$arrUserInfo['USERID'],
									'USERNAME'=>$arrUserInfo['USERNAME'] 
							)),31536000);
							load_lib('/bll/member/app');
							$clsApp=new bll_member_app();
							$arrAutoLoginList=$clsApp->getAutoLoginURL($arrUserInfo['USERID'],$arrUserInfo['USERNAME'],$this->getTime(),array( 
									'LASTUPD'=>$arrUserInfo['LASTUPD'] 
							));
							$this->setData('strReturnURL',$strReturnURL);
							$this->setData('arrAutoLoginList',$arrAutoLoginList);
							return '/loginapp';
						}
					}else{
						$this->setViewState('frmLogin','txtLoginValue','');
						$this->setViewState('frmLogin','hidAction','login');
					}
					load_controller('/reg');
					$this->setData('strRegURL',regcontroller::getURL());
					break;
				case 'reg':
					$strAction=$this->getParam('hidAction','post');
					if('reg'==$strAction){
						$strUserName=$this->getParam('txtUserName','post');
						$strUserPwd=$this->getParam('pwdUserPwd','post');
						$strUserPwdCfm=$this->getParam('pwdUserPwdCfm','post');
						load_lib('/bll/member/login');
						$clsBll=new bll_member_login();
						$mixResult=$clsBll->regUser($strUserName,$strUserPwd,$strUserPwdCfm,$this->getClientIP(),$this->getTime());
						if(is_array($mixResult)){
							$arrErrInfo=$mixResult;
						}else{
							$arrUserInfo=array( 
									'USERID'=>$mixResult,
									'USERNAME'=>$strUserName 
							);
							$this->setCookie('mauthcode',$clsBll->encryptLoginInfo($arrUserInfo),31536000);
							load_lib('/bll/member/app');
							$clsApp=new bll_member_app();
							$arrAutoLoginList=$clsApp->getAutoLoginURL($arrUserInfo['USERID'],$arrUserInfo['USERNAME'],$this->getTime());
							$this->setData('strReturnURL',$strReturnURL);
							$this->setData('arrAutoLoginList',$arrAutoLoginList);
							return '/loginapp';
						}
					}else{
						$this->setViewState('frmReg','txtUserName','');
						$this->setViewState('frmReg','hidAction','reg');
					}
					break;
				case 'logout':
					$strAuthCode=$this->getParam('mauthcode','c');
					load_lib('/bll/member/base');
					$clsBll=new bll_member_base();
					$arrUserInfo=$clsBll->decryptLoginInfo($strAuthCode);
					$this->setCookie('mauthcode','',-1);
					load_lib('/bll/member/app');
					$clsApp=new bll_member_app();
					$arrAutoLogoutList=$clsApp->getAutoLogoutURL($arrUserInfo['USERID'],$arrUserInfo['USERNAME'],$this->getTime());
					$this->setData('strReturnURL',$strReturnURL);
					$this->setData('arrAutoLogoutList',$arrAutoLogoutList);
					return '/logoutapp';
					break;
				default:
					break;
			}
		}else{
			$arrErrInfo[]=$mixAppChk;
		}
		//$this->addHeader('Content-type:text/json');
		$this->setData('arrErrInfo',$arrErrInfo);
		$this->setData('jsonErrInfo',json_encode($arrErrInfo));
		return '/app';
	}
}